"""
@ProjectName : pythontest
@File        : generator_Demo.py
@Author      : WorldWind(1772830365@qq.com)
@Address     : ChangSha - BoWeiFeng
@Date        : 2025/7/16 上午10:13
"""


# def generateNumber():
#     result = []
#     for i in range(10):
#         result.append(i)
#     return result
# 生成器函数
def generate():
    for i in range(10):
        yield i  # yield 关键字特点: 会返回后面的变量的值,相当于return
        # yield之后,不会结束函数运行,会记住上次运行的现场


def fibonacci():
    prev = 0
    curr = 1
    while True:
        yield curr
        prev, curr = curr, prev + curr


if __name__ == '__main__':
    # print(generateNumber())
    # gen = generate()
    # i1 = next(gen)
    # print(i1)
    gen = fibonacci()
    print(next(gen))
    print(next(gen))
    print(next(gen))
    print(next(gen))
    print(next(gen))
    print(next(gen))
    print(next(gen))
